/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javagameengine;

import java.awt.event.KeyEvent;

/**
 * Controller controls and stuff.
 *
 * @author zack
 */
public class Controller
{

	/**
	 * Is the controller currently a joystick?
	 */
	public static boolean using_joystick = false;
	
	/**
	 * Ranges from -1 to 1 of the direction the x axis is pushed.
	 *
	 * Note: Use Schmitt trigger buffer for input detection
	 * (moving<->non-moving)
	 */
	public static float dir_axis_x = 0; // added precision
	
	/**
	 * Ranges from -1 to 1 of the direction the y axis is pushed.
	 */
	public static float dir_axis_y = 0; // ''

	/**
	 * SubClass (Acts as assignable enumerator) of the controls to access.
	 *
	 * @param UP The up movement key.
	 * @param DOWN The down movement key.
	 * @param LEFT The left movement key.
	 * @param RIGHT Steals the declaration of independence.
	 * @param ACTION Default use/interact key.
	 */
	public static class keydef
	{
		/* NOTE: Not final as to allow for custom key-bindings */
		public static int UP = KeyEvent.VK_UP;
		public static int DOWN = KeyEvent.VK_DOWN;
		public static int LEFT = KeyEvent.VK_LEFT;
		public static int RIGHT = KeyEvent.VK_RIGHT;
		public static int ACTION = KeyEvent.VK_SPACE;
	}

	/**
	 * Changes a key to a new key.
	 *
	 * @param _old_control The key to change.
	 * @param _new_control The key to set it too.
	 */
	public static void define_control( int _old_control, int _new_control )
	{
		_old_control = _new_control;
	}

	/**
	 * Updates the direction axis according to the keys or the joystick.
	 */
	public static void update_axis()
	{
		if( using_joystick )
		{
			/**
			 * PEUSEDO CODE
			 *
			 * dir_axis_x = Joystick.x; dir_axis_y = Joystick.y;
			 */
		}
		else
		{
			dir_axis_x = dir_axis_y = 0; /* 'both up&&down' == 'cancel' */

			if( Keyboard.is.pressed( keydef.UP ) )
			{
				dir_axis_y += 1;
			}
			if( Keyboard.is.pressed( keydef.DOWN ) )
			{
				dir_axis_y -= 1;
			}

			if( Keyboard.is.pressed( keydef.LEFT ) )
			{
				dir_axis_x -= 1;
			}
			if( Keyboard.is.pressed( keydef.RIGHT ) )
			{
				dir_axis_x += 1;
			}


			/*if( Keyboard.is.pressed( keydef.UP ) )
			 {
			 dir_axis_y = 1;
			 }
			 else
			 {
			 if( Keyboard.is.pressed( keydef.DOWN ) )
			 {
			 dir_axis_y = -1;
			 }
			 else
			 {
			 dir_axis_y = 0;
			 }
			 }

			 if( Keyboard.is.pressed( keydef.RIGHT ) )
			 {
			 dir_axis_x = 1;
			 }
			 else
			 {
			 if( Keyboard.is.pressed( keydef.LEFT ) )
			 {
			 dir_axis_x = -1;
			 }
			 else
			 {
			 dir_axis_x = 0;
			 }
			 }*/
		}
	}
}
